package com.example.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.Netty4ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * 服务提供者
 *
 * @author tongyufu
 */
@EnableDiscoveryClient
@SpringBootApplication
//开启断路器
@EnableCircuitBreaker
public class UserServiceCloudApplication {

    /**
     * 服务提供者
     *
     * @param args 启动参数
     */
    public static void main(String[] args) {
        SpringApplication.run(UserServiceCloudApplication.class, args);
    }

    /**
     * Ribbon，客户端负载均衡
     *
     * @return restTemplate
     */
    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate(new Netty4ClientHttpRequestFactory());
    }
}
